from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from rest_framework.response import Response
from utils.common_logger import logger

class LoggerView(APIView):
    def get(self, request):
        logger.info('日志info')
        logger.error('日志error')
        return Response('日志测试')

#测试全局异常
from utils.common_exception import PasswordError
class ExceptionView(APIView):
    def get(self, request):
        # 4/0
        raise PasswordError('密码错误!!!!!')
        return Response("全局异常测试")


from utils.common_response import APIResponse
#测试全局异常返回
class ResponseView(APIView):
    def get(self, request):
        return APIResponse(code=201)

#轮播图借口
#序列化 和数据库都有》自动生成路由
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import ListModelMixin
from utils.common_view import CommonListModelMixin

from .models import Banner
from .serializer import BannerSerializer
class BannerView(GenericViewSet,CommonListModelMixin):
    queryset = Banner.objects.filter(is_delete=False,is_show=True).order_by('orders')[0:3]
    serializer_class = BannerSerializer
